# Contributor: Henrik Riomar <henrik.riomar@gmail.com>
# Contributor: Antoine Fontaine <antoine.fontaine@epfl.ch>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=sway
pkgver=1.10
pkgrel=0
pkgdesc="i3-compatible window manager for Wayland"
url="https://swaywm.org/"
license="MIT"
arch="all"
makedepends="
	basu-dev
	cairo-dev
	eudev-dev
	gdk-pixbuf-dev
	json-c-dev
	libcap-utils
	libevdev-dev
	libinput-dev
	libxkbcommon-dev
	linux-pam-dev
	meson
	ninja
	pango-dev
	pcre2-dev
	scdoc
	wayland-dev
	wayland-protocols
	wlroots-dev
	"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-wallpapers::noarch
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	$pkgname-portalsconf
	swaybar
	swaynag
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/swaywm/sway/archive/$pkgver.tar.gz
	sway-portals.conf
	sway.desktop
	remove-aports-git-version.patch
	"
install="$pkgname-portalsconf.pre-install $pkgname-portalsconf.pre-upgrade"
options="setcap !check" # no test suite

# Remove when Alpine >= 3.21
replaces="sxmo-sway"
provides="sway-virtual sxmo-sway=$pkgver-r$pkgrel"
provider_priority=100

build() {
	abuild-meson \
		-Db_lto=true \
		-Dsd-bus-provider=basu \
		. output
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# for setting SCHED_RR scheduling policy
	# before starting the Wayland server
	setcap cap_sys_nice=+ep "$pkgdir"/usr/bin/sway

	install -D -m644 "$srcdir"/sway.desktop \
		-t "$pkgdir"/usr/share/wayland-sessions/
}

portalsconf() {
	pkgdesc="xdg-desktop-portal configuration of compatible portals for Sway"
	install_if="$pkgname=$pkgver-r$pkgrel xdg-desktop-portal>=1.17.0"

	install -Dm644 "$srcdir"/sway-portals.conf \
		-t "$subpkgdir"/usr/share/xdg-desktop-portal/
}

wallpapers() {
	pkgdesc="Wallpapers for Sway"
	license="CC0-1.0"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/share/backgrounds
}

swaybar() {
	pkgdesc="Standard bar for Sway"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin/swaybar
}

swaynag() {
	pkgdesc="CLI to show a warning or error message with buttons in Sway"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin/swaynag
}

sha512sums="
d5585fe85d8dfc66f12fc4a48f6883025b7906436f0f457094b6aff12896bdb85891aa0e95bbed5c64374d39a3078c8de097ca5959145251974aa29209bc5e07  sway-1.10.tar.gz
c10862928d839a5a8a3a8c235ab9df58b0ffb111b7a0b11e9110b39169ac37de6e7eb1d945ec3611fb213ba159f0e47afd97085faa6ee8238e4d06fed0d74d70  sway-portals.conf
327f11cc053b39816da76a62199ef40f564acc1fe474b013fc1fd594c448ae3da805bfc475b7c68cce3a17b4a261c5a4bc7e9e91a471f90f5cf4e95bbd937e6c  sway.desktop
7f7358beb6b77a933c6c38dc45bdea447a151dc59dfb5ac7c12219240363f8334cc6a9200845a4612f241e05833e76d71a69db7df64e600a893bca46ddd37e64  remove-aports-git-version.patch
"
